<?php
/*
 * 登陆页
 */
include_once dirname(__FILE__).'/controller.php';
class Control_login extends Controller {
    public function index() {
        $this->view['title'] = '登陆';
        $this->render('login/index.html');
    }
    public function login() {
        if($this->isPost()) {
            $username = $this->postString('username') ? $this->postString('username'):'';
            $passwd = $this->postString('passwd') ? base64_encode($this->postString('passwd')) :'';
            if(!$username||!$passwd) {
                goUrl('/login/index');
            }
            $m_login = new Model_mlogin();
            $user = $m_login->checkUser($username,$passwd);
            $user = $user[0];
            if($user && md5($passwd.$user['random'])==$user['password']) {
                $islogin = $this->setLogin($user['uid'], $user['username'], $user['password'], time()+3600*24);
                if($islogin) {
                    goUrl('/');
                }
            }
            goUrl('/login');
        }
    }
}
?>